# Maintainer: taozuhong <taozuhong@gmail.com>

_realname=scintilla
pkgbase=mingw-w64-${_realname}-gtk3
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-gtk3"
pkgver=5.1.4
pkgrel=1
pkgdesc="A text widget adding syntax highlighting and more to GNOME (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.scintilla.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
source=("https://www.scintilla.org/scintilla${pkgver//./}.tgz"
        "scintilla.pc")
sha256sums=('dc825c554989056b2631446c7ca28b147c94c365d923dd0a928ab7a11dd3a365'
            'b8f27ae48cd30790444e6d1e02b117ef0f2bb048516ea7bf69ca48f77c9eea7b')

prepare() {
  cd ${_realname}
  export windir=${WINDIR}
}

build() {
  cd ${srcdir}/${_realname}/gtk
  make GTK3=1 PREFIX='${MINGW_PREFIX}' BUILD='${MINGW_CHOST}' HOST='${MINGW_CHOST}' TARGET='${MINGW_CHOST}'

  cp -f "${srcdir}/${_realname}.pc" "${srcdir}/${_realname}/bin/${_realname}.pc"
  sed -i -e "s#@prefix@#${MINGW_PREFIX}#g" "${srcdir}/${_realname}/bin/${_realname}.pc"
  sed -i -e "s#@version@#${pkgver}#g" "${srcdir}/${_realname}/bin/${_realname}.pc"
}

package() {
  # pkg-config
  install -Dm644 "${srcdir}/${_realname}.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}-gtk3.pc"

  # library
  install -Dm644 "${srcdir}/${_realname}/bin/scintilla.a" "${pkgdir}${MINGW_PREFIX}/lib/scintilla.a"
  install -Dm644 "${srcdir}/${_realname}/bin/libscintilla.dll" "${pkgdir}${MINGW_PREFIX}/bin/libscintilla.dll"

  # include
  mkdir -p ${pkgdir}${MINGW_PREFIX}/include/${_realname}
  install -Dm644 ${srcdir}/${_realname}/include/*.h ${pkgdir}${MINGW_PREFIX}/include/${_realname}

  # License
  install -Dm644 "${srcdir}/${_realname}/License.txt" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/License.txt"
  install -Dm644 "${srcdir}/${_realname}/version.txt" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/version.txt"
  install -Dm644 "${srcdir}/${_realname}/README" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/README"
}
